Repository navigation
native interop: fix syslog on Apple arm64, stop starting getprop - #325
Conversation
- SystemInfo ran "getprop ro.build.user" on every Unix host, via PATH - first PATH match decided the answer - now /system/bin/getprop, plus the platform itself off net462 - System.Diagnostics.Process out of the startup path audit da18b6f-f048
ed5e345 to
7842360
Compare
- process level env var tests restore through a using, not by hand - ProcessLevelEnvironmentVariable leaked the variable on a failed assert - Machine and User targets keep cleaning up themselves, not covered
- FormatMessage allocates with LocalAlloc, the ref string marshalling freed it as COM task memory - now out IntPtr, PtrToStringUni over the returned length, LocalFree in a finally - hygiene, not a fix: the probe found the block inside the process heap - WindowsAllocatorProbeTest replaced by NativeErrorTest audit da18b6f-f045
- a variadic argument goes on the stack on Apple arm64, a fixed one in a register, so the callee read the wrong slot - declaring it variadic is out: CoreCLR refuses a __arglist P/Invoke - only the two fixed parameters now, record as the format string with every percent sign doubled - logged text, length and platforms that worked stay as they were - VariadicAbiProbeTest replaced by the escaping and signature tests audit da18b6f-f046
- SystemInfo ran "getprop ro.build.user" on every Unix host, via PATH - first PATH match decided the answer - now /system/bin/getprop, plus the platform itself off net462 - System.Diagnostics.Process out of the startup path audit da18b6f-f048
- process level env var tests restore through a using, not by hand - ProcessLevelEnvironmentVariable leaked the variable on a failed assert - Machine and User targets keep cleaning up themselves, not covered
- FormatMessage allocates with LocalAlloc, the ref string marshalling freed it as COM task memory - now out IntPtr, PtrToStringUni over the returned length, LocalFree in a finally - hygiene, not a fix: the probe found the block inside the process heap - WindowsAllocatorProbeTest replaced by NativeErrorTest audit da18b6f-f045
- a variadic argument goes on the stack on Apple arm64, a fixed one in a register, so the callee read the wrong slot - declaring it variadic is out: CoreCLR refuses a __arglist P/Invoke - only the two fixed parameters now, record as the format string with every percent sign doubled - logged text, length and platforms that worked stay as they were - VariadicAbiProbeTest replaced by the escaping and signature tests audit da18b6f-f046
56334ea to
7202528
Compare
|
Implementation plan for #325, kept here for the record. Revised after the merge so that it describes the change as it landed. PlanPR #325: the native interop clusterf045, f046 and f048 of scan
Branch Commit 0: bring the probes over"Probes for f045 & f046" lives on the #324 branch before its reset; cherry-pick it onto the new
Commit 1: f048, detect Android without running a process
Both cheap answers, in this order, and no process at all:
if (Environment.OSVersion.Platform != PlatformID.Unix)
{
return false;
}
if (File.Exists("/system/bin/getprop"))
{
return true;
}
// then the platform's own answer, per target, see aboveWhat it buys beyond the finding: no process spawn at every Unix start, no Test,
Changelog Commit 1b: restore environment variables through a usingWhile there, the two process-level environment variable tests in Commit 2: f045, release the FormatMessage buffer with LocalFree
Answered by the #324 run: the Windows job is green, so Either way the correct shape is the same. internal static extern int FormatMessage(
int dwFlags, IntPtr lpSource, int dwMessageId, int dwLanguageId,
out IntPtr lpBuffer, int nSize, IntPtr arguments);
[DllImport("Kernel32.dll", SetLastError = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
internal static extern IntPtr LocalFree(IntPtr memory);
Test, new
Delete Changelog Commit 3: f046, drop the variadic argument from the syslog call
Answered, and the finding holds. On the #324 run 35646327969 the macOS job failed with The argument was passed in a register, the callee read it off the stack. The same probe passes on Declaring it variadic is not available: CoreCLR answers a // NativeMethods.cs
internal static extern void syslog(int priority, string format);
// LocalSyslogAppender.Append
NativeMethods.syslog(priority, EscapePercent(line));
private static string EscapePercent(string message)
=> message.IndexOf('%') < 0 ? message : message.Replace("%", "%%");
Tests in
Delete Changelog Verification
|
Fixed
LocalSyslogAppenderpassed a variadic argument tosyslog(3), audit da18b6f-f046read a slot the runtime never wrote: stack bytes in the system log, or a crash
__arglistP/Invoke, so only the two fixedparameters are declared and the record goes in as the format string with every
%doubledChanged
SystemInforangetprop ro.build.userat type initialisation on every Unix host, offPATH,so the first match there decided the answer
/system/bin/getprop, and the platform itself off net462FormatMessagebuffer was released by the wrong allocator, audit da18b6f-f045LocalAlloc, theref stringmarshalling freed it as COM task memoryout IntPtr,PtrToStringUniover the returned length,LocalFreein afinallyTests